package main

import (
	"log"
	"os/exec"
	"sync"
)

var services = []struct {
	dir string // 服务所在目录，相对于启动程序的路径
	cmd string // 启动命令
}{
	// 从cmd/start目录到services的相对路径是"../../services/服务名"
	{"../../services/business-service", "go run main.go"},
	{"../../services/auth-service", "go run main.go"},
	{"../../services/traffic-service", "go run main.go"},
	{"../../services/route-service", "go run main.go"},
	{"../../services/monitor-service", "go run main.go"},
}

func main() {
	var wg sync.WaitGroup

	for i, s := range services {
		wg.Add(1)
		go func(index int, dir, cmd string) {
			defer wg.Done()
			log.Printf("启动服务 %d: %s\n", index+1, dir)

			// 创建命令对象
			cmdObj := exec.Command("cmd", "/C", cmd)
			cmdObj.Dir = dir

			// 执行命令（阻塞）
			if err := cmdObj.Run(); err != nil {
				log.Printf("服务 %s 启动失败: %v\n", dir, err)
			}
		}(i, s.dir, s.cmd)
	}

	log.Println("所有服务启动完成（按Ctrl+C停止）")
	wg.Wait()
}
